<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript"></script>
</head>
<body>

<div>
    <p><input type="text" id="username" placeholder="账户"></p>
    <p><input type="password" id="password" placeholder="密码"></p>
</div>
<p><button id="btn2">登录</button></p>
<p><button id="btn1">发送ajax请求1</button></p>

</body>
<script type="text/javascript">
    let btn2 = document.querySelector("#btn2");
    btn2.addEventListener('click', e=>{
        let data = {
            username:document.getElementById("username").value,
            password:document.getElementById("password").value
        }
        console.log(data)
        data = JSON.stringify(data)
        console.log(data)
        fetch('http://localhost:80/user/login.do',{
            'method':'post',
            'mode':'cors',
            "Access-Control-Allow-Origin" : '*',
            "Access-Control-Allow-Credentials" : true,
            'headers':{
                'content-type':'application/json'
            },
            'body':data
        }).then(
        rs => {
            console.log(rs)
        })
    })
</script>
</html>